/*
 * File         : cym_system.h
 * Version      : 0.3.0
 * Author       : Vincent Cheung
 * Date         : Oct. 16, 2013
 * Description  : All the kernel API here for this system.
 *
 * Copyright (C) 2013, CYM Co., Ltd.
 *
 * Change Logs  :
 * Date                 Author          Notes
 * Oct. 16, 2013        Vincent         first version
 * Nov. 11, 2013        Vincent         move cym_clock.h, cym_timer.h, cym_device.h
 *                                      and cym_net_device.h to this file
 * Nov. 18, 2013        Vincent         add key support
 *
 */

#ifndef __CYM_SYSTEM_H__
#define __CYM_SYSTEM_H__

#include "cym_def.h"
#include "cym_cpu.h"
#include "cym_list.h"
#include "cym_irq.h"

/*
 * timer management: clock & timer interface
 */
utick_t cym_tick_get(void);
void cym_tick_set(utick_t tick);
void cym_tick_increase(void);
#ifdef CYM_USING_HIGH_PREC_TIMER
utick_t cym_tick_high_prec_get(void);
void cym_tick_high_prec_increase(void);
#endif	/* CYM_USING_HIGH_PREC_TIMER */

serr_t cym_timer_init(p_timer_t timer, void (*timeout)(void *parameter),
                         void *parameter, utime_t time, 
                         uint8_t period_flag, uint8_t type_flag);
p_timer_t cym_timer_create(void (*timeout)(void *parameter), void *parameter, 
                             utime_t time, uint8_t period_flag, uint8_t type_flag);
serr_t cym_timer_delete(p_timer_t timer);
serr_t cym_timer_start(p_timer_t timer);
serr_t cym_timer_stop(p_timer_t timer);
serr_t cym_timer_control(p_timer_t timer, uint8_t cmd, void *arg);
struct sync_info *cym_sync_info_get(uint8_t frequency);

/*
 * device management: device interface
 */
serr_t cym_device_register(p_device_t dev, const char *name, uint16_t flags);
serr_t cym_device_init_all(void);
serr_t cym_device_init(p_device_t dev);
p_device_t cym_device_find(const char *name);
serr_t cym_device_open(p_device_t dev, uint16_t oflag);
serr_t cym_device_close(p_device_t dev);
usize_t cym_device_read(p_device_t dev, uoff_t pos, void *buffer, usize_t size);
usize_t cym_device_write(p_device_t dev, uoff_t pos,
                            const void *buffer, usize_t size);
serr_t cym_device_control(p_device_t dev, uint8_t cmd, void *arg);
serr_t cym_device_set_rx_indicate(p_device_t dev, serr_t (*rx_ind)(
                                     p_device_t dev, usize_t size));
serr_t cym_device_set_tx_complete(p_device_t dev, serr_t (*tx_done)(
                                     p_device_t dev, void *buffer));

/*
 * net device management: net device interface
 */
#ifdef CYM_USING_NET
serr_t cym_net_init(struct net_device *net_dev, const char *name, uint16_t flags);
struct net_package *cym_net_rx(p_device_t dev);
serr_t cym_net_tx(p_device_t dev, struct net_package *pack);
#endif	/* CYM_USING_NET */

/*
 * key management: key interface
 */
#ifdef CYM_USING_KEY
void cym_key_register(struct key_module *mod);
void cym_key_init(void);
void cym_key_add(struct key_state *stat, uint8_t num);
void cym_key_add_listener(struct key_listener *listener);
#endif	/* CYM_USING_KEY */

#endif	/* __CYM_SYSTEM_H__ */